package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.ProductVisit;
import com.nbsaas.boot.product.api.domain.request.ProductVisitRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.product.data.entity.Product;
            import com.nbsaas.boot.jpa.data.entity.User;
            import com.nbsaas.boot.shop.data.entity.Shop;

/**
* 商品浏览记录请求对象转换成实体对象
*/

public class ProductVisitEntityConvert  implements Converter<ProductVisit, ProductVisitRequest> {

    @Override
    public ProductVisit convert(ProductVisitRequest source) {
        ProductVisit result = new ProductVisit();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getProduct()!=null){
                    Product product =new Product();
                    product.setId(source.getProduct());
                    result.setProduct(product);
                    }
                    if(source.getCreator()!=null){
                    User creator =new User();
                    creator.setId(source.getCreator());
                    result.setCreator(creator);
                    }
                    if(source.getShop()!=null){
                    Shop shop =new Shop();
                    shop.setId(source.getShop());
                    result.setShop(shop);
                    }
        return result;
    }
}

